﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Xc.WaterMeters.ServerHosts.Migrations
{
    public partial class M0 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "DeviceInfos",
                columns: table => new
                {
                    Id = table.Column<ulong>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    DeviceId = table.Column<string>(type: "TEXT", nullable: true),
                    CurrentValue = table.Column<decimal>(type: "TEXT", nullable: false),
                    CreateDateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    UpdateDateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    IsDelete = table.Column<bool>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DeviceInfos", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "AlarmInfoHistorys",
                columns: table => new
                {
                    Id = table.Column<ulong>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    CreateDateTime = table.Column<DateTime>(type: "TEXT", nullable: false),
                    DeviceInfoId = table.Column<ulong>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Value = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AlarmInfoHistorys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AlarmInfoHistorys_DeviceInfos_DeviceInfoId",
                        column: x => x.DeviceInfoId,
                        principalTable: "DeviceInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "AlarmInfos",
                columns: table => new
                {
                    Id = table.Column<ulong>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    DeviceInfoId = table.Column<ulong>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Value = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AlarmInfos", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AlarmInfos_DeviceInfos_DeviceInfoId",
                        column: x => x.DeviceInfoId,
                        principalTable: "DeviceInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "CommandInfos",
                columns: table => new
                {
                    Id = table.Column<ulong>(type: "INTEGER", nullable: false),
                    CommandName = table.Column<string>(type: "TEXT", nullable: true),
                    CommandId = table.Column<ulong>(type: "INTEGER", nullable: false),
                    DeviceInfoId = table.Column<ulong>(type: "INTEGER", nullable: false),
                    RequestInfo_SendContent = table.Column<byte[]>(type: "BLOB", nullable: true),
                    RequestInfo_SendObject = table.Column<string>(type: "TEXT", nullable: true),
                    RequestInfo_CreateDateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    RespondInfo_RespondDateTime = table.Column<DateTime>(type: "TEXT", nullable: true),
                    RespondInfo_RespondContent = table.Column<byte[]>(type: "BLOB", nullable: true),
                    RespondInfo_RespondObject = table.Column<string>(type: "TEXT", nullable: true),
                    Status = table.Column<int>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CommandInfos", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CommandInfos_DeviceInfos_DeviceInfoId",
                        column: x => x.DeviceInfoId,
                        principalTable: "DeviceInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "PropertyInfoHistorys",
                columns: table => new
                {
                    Id = table.Column<ulong>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    DateTimeCreate = table.Column<DateTime>(type: "TEXT", nullable: false),
                    DeviceInfoId = table.Column<ulong>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Value = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PropertyInfoHistorys", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PropertyInfoHistorys_DeviceInfos_DeviceInfoId",
                        column: x => x.DeviceInfoId,
                        principalTable: "DeviceInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "PropertyInfos",
                columns: table => new
                {
                    Id = table.Column<ulong>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    DeviceInfoId = table.Column<ulong>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Value = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PropertyInfos", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PropertyInfos_DeviceInfos_DeviceInfoId",
                        column: x => x.DeviceInfoId,
                        principalTable: "DeviceInfos",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AlarmInfoHistorys_DeviceInfoId",
                table: "AlarmInfoHistorys",
                column: "DeviceInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_AlarmInfos_DeviceInfoId",
                table: "AlarmInfos",
                column: "DeviceInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_CommandInfos_DeviceInfoId",
                table: "CommandInfos",
                column: "DeviceInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_PropertyInfoHistorys_DeviceInfoId",
                table: "PropertyInfoHistorys",
                column: "DeviceInfoId");

            migrationBuilder.CreateIndex(
                name: "IX_PropertyInfos_DeviceInfoId",
                table: "PropertyInfos",
                column: "DeviceInfoId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AlarmInfoHistorys");

            migrationBuilder.DropTable(
                name: "AlarmInfos");

            migrationBuilder.DropTable(
                name: "CommandInfos");

            migrationBuilder.DropTable(
                name: "PropertyInfoHistorys");

            migrationBuilder.DropTable(
                name: "PropertyInfos");

            migrationBuilder.DropTable(
                name: "DeviceInfos");
        }
    }
}
